{include file="common/header"/}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-card-body">
                <div class="layui-row">
                    <form action="" class="layui-form">
                    <div class="layui-row layui-col-space10">
                      <div class="layui-col-md2 layui-col-xs4">
                        <input type="text" name="" id="keys" lay-verify="required" placeholder="请输入" class="layui-input">
                      </div>
                      <div class="layui-col-md2 layui-col-xs4">
                        <input type="button" id="searchBtn" name="submit" class="layui-btn" value="搜索">
                      </div>
                    </div>
                  </form>
                </div>
                <div class="layui-row">
                    <table class="layui-table" id="list" lay-filter="list"></table>
                </div>
              </div>
            </div>
        </div>
    </div>
</div>
{include file="common/footer"/}

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-sm" onclick="open_frame('{:lang('add')}','{:url("add")}');"><i class="layui-icon layui-icon-add-circle"></i>{:lang('add')}</a>
        <a data-href="{:url('del')}"  class="layui-btn layui-btn-sm layui-btn-danger" id="delAll">{:lang('delete checked')}</a>
    </div>
    
</script>
<script type="text/html" id="status">
    <input type="checkbox" name="status" data-href="{:url('State')}" value="{{d.id}}" lay-skin="switch" lay-text="显示|隐藏" lay-filter="status" {{ d.status == 'normal' ? 'checked' : '' }}>
</script>
<script type="text/html" id="order">
    <input name="{{d.id}}" data-id="{{d.id}}" class="layui-input list_order" value=" {{d.sort}}" size="10"/>
</script>

<script type="text/html" id="action">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-xs" onclick="open_frame('{:lang('edit')}','{:url("edit")}?id={{d.id}}');">{:lang('edit')}</a>
        <a data-href="{:url('del')}" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
    </div>
</script>

<script type="text/html" id="titleTpl">
    {{d.title}}<img src="/static/admin/images/image.gif" onmouseover="layer.tips('<img src={{d.image}}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();">
</script>

<script>
var table;
var searchObj = {};

layui.use(['table','form'], function() {
    table = layui.table;
    var form = layui.form,$ = layui.jquery;
    table.render({
        elem: '#list',
        url: '{:url("index")}',
        method: 'post',
        where:searchObj,
        title: '广告列表',
        toolbar: '#toolbarDemo', 
        defaultToolbar: [],
        id:'list',
        cols: [[
            {checkbox: true, fixed: true},
            {field: 'id', title: 'ID', width: 80, fixed: true, sort: true},
            {field: 'name', title: '标识' },
            {field: 'title', title: '广告名称', templet:"#titleTpl"},
            {field: 'create_time', title: '添加时间' },
            {field: 'sort', title: '排序', width: 120, templet:"#order"},
            {field: 'status', title: '状态', width: 180, templet:'#status'},
            {title:'操作',width:150, toolbar: '#action',align:"center"},
        ]],
        limits: [10, 15, 20, 25, 50, 100],
        limit: 15,
        page: true
    });
    
    //搜索
    $('#searchBtn').on('click', function () {
        searchObj['title'] = $('#keys').val();
        table.reload('list',{where:searchObj});
    });
    $('body').on('blur','.list_order',function() {
        var ad_id = $(this).attr('data-id');
        var sort = $(this).val();
        var loading = layer.load(1, {shade: [0.1, '#fff']});
        $.post('{:url("order")}',{id:ad_id,sort:sort},function(res){
            layer.close(loading);
            if(res.code === 1){
                layer.msg(res.msg, {time: 1000, icon: 1});
                window.location.reload();
            }else{
                layer.msg(res.msg,{time:1000,icon:2});
            }
        })
    });
})
</script>